package com.misyi.designpattern.prototype;

import lombok.Data;
import org.openjdk.jol.vm.VM;

/**
 * 没有使用原型模式
 *
 * @author licong
 * @date 2021-09-12 下午7:36
 */
public class WithoutPrototypePatternDemo {

    public static void main(String[] args) {
        Product product = new Product();
        product.setName("测试产品名称");
        Component component = new Component();
        component.setName("测试组件名称");
        product.setComponent(component);

        // 进行拷贝
        Product copyProduct = new Product();
        copyProduct.setName(product.getName());
        copyProduct.setComponent(product.getComponent());

        System.out.println(copyProduct);

        // 对比地址值
        System.out.println(VM.current().addressOf(product));
        System.out.println(VM.current().addressOf(copyProduct));
        System.out.println(VM.current().addressOf(product.getComponent()));
        System.out.println(VM.current().addressOf(copyProduct.getComponent()));
    }



    @Data
    public static class Product {

        private String name;

        private Component component;

    }


    @Data
    private static class Component {
        private String name;
    }

}
